package com.clz.servlet;

import com.clz.servise.Impl.UserServiceImpl;
import com.clz.servise.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/SignIn")
public class SignInServlet extends HttpServlet {
    private UserService userService =new UserServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String name =req.getParameter("username");
        String psw=req.getParameter("password");
        if (userService.signIn(name, psw)){
            resp.setContentType("text/html;charset=UTF-8");
            PrintWriter out =resp.getWriter();
            out.println("<script>alert(\"恭喜你，注册成功！\");window.location.href = \"login.html\"</script>");
        }else {
            resp.sendRedirect("signIn.html?login=false1");
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
    }
}
